package com.justnow;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 使用ReentrantLock类实现同步
 */

class LockThread implements Runnable{

    private Lock lock = new ReentrantLock();

    @Override
    public void run() {
        lock.lock();
        for (int i = 0; i < 5; i++) {
            System.out.println("当前线程名：" + Thread.currentThread() + "i = " + i);
        }
        lock.unlock();
    }
}
public class LockThreadDemo {
    public static void main(String[] args) {
        LockThread lockThread = new LockThread();
        new Thread(lockThread).start();
        new Thread(lockThread).start();
        new Thread(lockThread).start();
    }
}

